<script setup>
import { ref } from 'vue'
import { useVModel } from '@vueuse/core'

const props = defineProps({
  modelValue: Boolean,
  detail: Object
})
const emits = defineEmits(['submit', 'update:modelValue'])
const dialogVisible = useVModel(props, 'modelValue', emits)

const ruleForm = ref({
  deviceCommand: ''
})
const rules = {}

const ruleFormRef = ref()
const handleSubmit = async () => {
  await ruleFormRef.value.validate()
  emits('submit', ruleForm.value)
}

const handleClose = done => done()

const handleOpen = () => {
  ruleFormRef.value.resetFields()

  // if (props.detail) {
  //   ruleForm.value.deviceCommand = props.detail.deviceCommand
  // }
}
</script>

<template>
  <el-dialog
    v-model="dialogVisible"
    width="768px"
    :before-close="handleClose"
    :close-on-click-modal="false"
    v-bind="$attrs"
    @open="handleOpen"
  >
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="100px"
      label-position="right"
      label-suffix="："
    >
      <el-form-item label="指令" prop="deviceCommand">
        <el-input v-model="ruleForm.deviceCommand" clearable />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false"> 取消 </el-button>
      <el-button type="primary" @click="handleSubmit"> 确认 </el-button>
    </template>
  </el-dialog>
</template>
